﻿@model InstallModel
@using IT.CMS.Core.Infrastructure;
@using IT.CMS.Web.Models.Install;
@using IT.CMS.Web.Infrastructure.Installation;
@{
    var ILS = EngineContext.Current.Resolve<IInstallationLocalizationService>();
}

@{
    ViewBag.Title = @ILS.GetResource("Title");
    Layout = "~/Views/shared/_BootstrapLayout.cshtml";
}

@section head {
        @if (ILS.GetCurrentLanguage().IsRightToLeft)
        {
        <link href="@Styles.Url("~/Content/bootstrap-rtl.css")" rel="stylesheet"/>
        <link href="@Styles.Url("~/Content/responsive-rtl.css")" rel="stylesheet"/>
        <link href="@Url.Content("~/Content/Install/style.rtl.css")" type="text/css" rel="stylesheet" />
        }
        else
        {
        <link href="@Styles.Url("~/Content/bootstrap.css")" rel="stylesheet"/>
        <link href="@Styles.Url("~/Content/bootstrap-responsive.css")" rel="stylesheet"/>
        <link href="@Url.Content("~/Content/Install/style.css")" type="text/css" rel="stylesheet" />
        }
        <link href="@Styles.Url("~/Content/bootstrap-mvc-validation.css")" rel="stylesheet"/>
}

@section Scripts {
        <script type="text/javascript">
            $(document).ready(function () {
                $('#installation-form').submit(function () {
                    if ($('#installation-form').valid()) {
                        window.setTimeout(function () {
                            $(".throbber").show();
                        }, 1000);

                        $('input[type=submit]', this).attr('disabled', 'disabled');
                    }
                });
            });

            $(document).ready(function () {
                $('input:radio[name=DataProvider]').click(toggleProvider);
                $('input:radio[name=SqlConnectionInfo]').click(toggleSqlConnectionInfo);

                $('input:radio[name=MongoDbConnectionInfo]').click(toggleMongoDbConnectionInfo);

                $('input:radio[name=SqlAuthenticationType]').click(toggleSqlAuthenticationType);
                $("input:checkbox[name=UseCustomCollation]").click(toggleCollation);

                toggleProvider();
                toggleSqlConnectionInfo();
                toggleSqlAuthenticationType();
                toggleCollation();
                toggleMongoDbConnectionInfo();
            });

            function toggleProvider() {
                var selectedProvider = $("input[name=DataProvider]:checked").attr('id');

                if (selectedProvider == 'provider_sqlce') {
                    $('#sqlConnectionInfo').hide();
                    $('#MongoDbConnectionInfo').hide();
                }
                else if (selectedProvider == 'provider_sqlserver') {
                    $('#MongoDbConnectionInfo').hide();
                    $('#sqlConnectionInfo').show();
                } else if (selectedProvider == 'provider_MongoDb') {
                    $('#sqlConnectionInfo').hide();
                    $('#MongoDbConnectionInfo').show();
                }
            }

            function toggleSqlConnectionInfo() {
                var selectedProvider = $("input[name=SqlConnectionInfo]:checked").attr('id');
                if (selectedProvider == 'sqlconnectioninfo_values') {
                    $('#sqlDatabaseInfo').show();
                    $('#sqlDatabaseConnectionString').hide();
                }
                else if (selectedProvider == 'sqlconnectioninfo_raw') {
                    $('#sqlDatabaseInfo').hide();
                    $('#sqlDatabaseConnectionString').show();
                }
            }


            function toggleMongoDbConnectionInfo() {
                var selectedProvider = $("input[name=MongoDbConnectionInfo]:checked").attr('id');


                if (selectedProvider == 'MongoDbConnectionInfo_data') {
                    $('#MongoDatabaseInfo').show();
                    $('#MongoDatabaseURI').hide();
                }
                else if (selectedProvider == 'MongoDbConnectionInfo_sUri') {
                    $('#MongoDatabaseInfo').hide();
                    $('#MongoDatabaseURI').show();
                }
            }


            function toggleSqlAuthenticationType() {
                var selectedProvider = $("input[name=SqlAuthenticationType]:checked").attr('id');
                if (selectedProvider == 'sqlauthenticationtype_sql') {
                    $('#pnlSqlServerUsername').show();
                    $('#pnlSqlServerPassword').show();
                }
                else if (selectedProvider == 'sqlauthenticationtype_windows') {
                    $('#pnlSqlServerUsername').hide();
                    $('#pnlSqlServerPassword').hide();
                }
            }

            function toggleCollation() {
                if ($('#UseCustomCollation').is(':checked')) {
                    $('#CollationDiv').show();
                }
                else {
                    $('#CollationDiv').hide();
                }
            }
        </script>
}


@using (Html.BeginForm("Index", "Install", FormMethod.Post, new { id = "installation-form" }))
{ 
<div class="tm_pad-shadow">
        <div class="tm_lifted">
            <div class="tm_text-shadow">



                <div style="text-align: center;"><span class="header-text">@ILS.GetResource("Title")</span></div>
                <br />

                <div class="alert alert-info">
                    <strong>@ILS.GetResource("Tooltip1")</strong>
                </div>



            @Html.Partial("_alerts")
            @Html.Partial("_validationSummary")

                <div class="bs-docs">
                    <div class="bs-doc-titile">@ILS.GetResource("InstallationLanguage")</div>
                    <div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("SelectInstallationLanguage")</span>
                        @Html.DropDownList("language", Model.AvailableLanguages, new { onchange = "window.location.href = this.value;", style = "width:313px;" })
                    </div>
                    <br />
                </div>

                <div class="bs-docs">
                    <div class="bs-doc-titile">@ILS.GetResource("AdministratorAccount")</div>
                    <div class="input-prepend">
                        <span class="add-on inputLable">@ILS.GetResource("AdminEmail")</span>
                       @Html.TextBoxFor(x => x.AdminEmail, new { @class = "textbox", style = "width:300px; direction: ltr;" })
                    </div>
                       @Html.ValidationMessage("AdminEmail", null, new { @class = "help-inline" })
                    <br />

                    <div class="input-prepend">
                        <span class="add-on inputLable">@ILS.GetResource("AdminPassword")</span>
                        @Html.PasswordFor(x => x.AdminPassword, new { @class = "textbox", style = "width:300px; direction: ltr;" })
                    </div>
                        @Html.ValidationMessage("AdminPassword", null, new { @class = "help-inline" })
                                        
                    <br />
                    <div class="input-prepend">
                        <span class="add-on inputLable">@ILS.GetResource("ConfirmPassword")</span>
                        @Html.PasswordFor(x => x.ConfirmPassword, new { @class = "textbox", style = "width:300px; direction: ltr;" })
                    </div>
                        @Html.ValidationMessage("ConfirmPassword", null, new { @class = "help-inline" })
                    <br />
                </div>

                <div class="bs-docs">
                    <div class="bs-doc-titile">@ILS.GetResource("DatabaseInformation")</div>

                    <table class="table">
                        <thead>
                            <tr>
                   <td>
                       <label class="radio">
                           @Html.RadioButton("DataProvider", "sqlce", (Model.DataProvider == "sqlce"), new { id = "provider_sqlce" })
                           @ILS.GetResource("SqlCompact")
                       </label>
                   </td>
                   <td>
                        <label class="radio">
                            @Html.RadioButton("DataProvider", "sqlserver", (Model.DataProvider == "sqlserver"), new { id = "provider_sqlserver" })
                            @ILS.GetResource("SqlStandard")
                        </label>
                   </td>
                   <td>
                        <label class="radio">
                               @Html.RadioButton("DataProvider", "MongoDb", (Model.DataProvider == "MongoDb"), new { id = "provider_MongoDb" })
                               @ILS.GetResource("UseMongoDb")
                        </label>
                                </td>
                            </tr>
                        </thead>
                    </table>
                    <hr class="databases" />

<div id="sqlConnectionInfo">
<table class="table">
                            <thead>
                                <tr>
                                    <td style="width:50%;">
                                        <label class="radio">
                                            @Html.RadioButton("SqlConnectionInfo", "sqlconnectioninfo_values", (Model.SqlConnectionInfo == "sqlconnectioninfo_values"), new { id = "sqlconnectioninfo_values" })
                                            @ILS.GetResource("ConnectionStringValues")
                                        </label>
                                    </td>
                                    <td style="width:50%;">
                                        <label class="radio">
                                            @Html.RadioButton("SqlConnectionInfo", "sqlconnectioninfo_raw", (Model.SqlConnectionInfo == "sqlconnectioninfo_raw"), new { id = "sqlconnectioninfo_raw" })
                                            @ILS.GetResource("RawConnectionString")
                                        </label>
                                    </td>
                                </tr>
                            </thead>
                        </table>

<div id="sqlDatabaseInfo">
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("SqlServerName")</span>
    @Html.TextBoxFor(x => x.SqlServerName, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div>
    @Html.ValidationMessage("SqlServerName", null, new { @class = "help-inline" })
    <br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("DatabaseName")</span>
    @Html.TextBoxFor(x => x.SqlDatabaseName, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div>
    @Html.ValidationMessage("SqlDatabaseName", null, new { @class = "help-inline" })
    <br />
<table class="table">
                                <thead>
                                    <tr>
                                        <td style="width:50%;">
                                            <label class="radio">
                                                @Html.RadioButton("SqlAuthenticationType", "sqlauthentication", (Model.SqlAuthenticationType == "sqlauthentication"), new { id = "sqlauthenticationtype_sql" })
                                                @ILS.GetResource("SqlAuthentication")
                                            </label>
                                        </td>
                                        <td style="width:50%;">
                                            <label class="radio">
                                                @Html.RadioButton("SqlAuthenticationType", "windowsauthentication", (Model.SqlAuthenticationType == "windowsauthentication"), new { id = "sqlauthenticationtype_windows" })
                                                @ILS.GetResource("WindowsAuthentication")
                                            </label>
                                        </td>
                                    </tr>
                                </thead>
</table>

<div class="input-prepend" id="pnlSqlServerUsername"><span class="add-on inputLable">@ILS.GetResource("SqlServerUsername")</span>
    @Html.TextBoxFor(x => x.SqlServerUsername, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div>
    @Html.ValidationMessage("SqlServerUsername", null, new { @class = "help-inline" })
    <br />
<div class="input-prepend" id="pnlSqlServerPassword"><span class="add-on inputLable">@ILS.GetResource("SqlServerPassword")</span>
    @Html.TextBoxFor(x => x.SqlServerPassword, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div>
    @Html.ValidationMessage("SqlServerPassword", null, new { @class = "help-inline" })
    <br />
</div>

<div id="sqlDatabaseConnectionString">
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("ConnectionString")</span>
    @Html.TextBoxFor(x => x.DatabaseConnectionString, new { @class = "textbox", style = "width:525px; direction: ltr;" })</div>
    @Html.ValidationMessage("DatabaseConnectionString", null, new { @class = "help-inline" })
<span class="hint">@ILS.GetResource("Example"):<br /><br />
<code>Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;UserID=userName;Password=password</code></span>
</div>
<hr class="databases" />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("CreateDatabaseIfDoesNotExist")</span><div class="input-append"><span class="add-on">@Html.CheckBoxFor(x => x.SqlServerCreateDatabase)</span></div></div><br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("CustomCollation")</span><div class="input-append"><span class="add-on">@Html.CheckBoxFor(x => x.UseCustomCollation)</span></div></div><br />
<div class="input-prepend" id="CollationDiv"><span class="add-on inputLable">@ILS.GetResource("CustomCollation")</span>
    @Html.TextBoxFor(x => x.Collation, new { @class = "textbox", style = "width:300px; direction: ltr;" })
</div>
</div>


<div id="MongoDbConnectionInfo">
<table class="table">
                            <thead>
                                <tr>
                                    <td style="width:50%;">
                                        <label class="radio">
                                            @Html.RadioButton("MongoDbConnectionInfo", "MongoDbConnectionInfo_data", (Model.MongoDbConnectionInfo == "MongoDbConnectionInfo_data"), new { id = "MongoDbConnectionInfo_data" })
                                            @ILS.GetResource("ConnectionStringValues")
                                        </label>
                                    </td>
                                    <td style="width:50%;">
                                        <label class="radio">
                                            @Html.RadioButton("MongoDbConnectionInfo", "MongoDbConnectionInfo_sUri", (Model.MongoDbConnectionInfo == "MongoDbConnectionInfo_sUri"), new { id = "MongoDbConnectionInfo_sUri" })
                                            @ILS.GetResource("EnterMongoDbConnectionUri")
                                        </label>
                                    </td>
                                </tr>
                            </thead>
                        </table>
<div id="MongoDatabaseInfo">
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("SqlServerName")</span>@Html.TextBoxFor(x => x.MongoDbServerName, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div><br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("DbServerPort")</span>@Html.TextBoxFor(x => x.MongoDbServerPort, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div><br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("SqlServerUsername")</span>@Html.TextBoxFor(x => x.SqlServerUsername, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div><br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("SqlServerPassword")</span>@Html.TextBoxFor(x => x.SqlServerPassword, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div><br />
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("DatabaseName")</span>@Html.TextBoxFor(x => x.MongoDbDatabaseName, new { @class = "textbox", style = "width:300px; direction: ltr;" })</div><br />
</div>

<div id="MongoDatabaseURI">
<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("MongoDbConnectionUri")</span>
    @Html.TextBoxFor(x => x.MongoDbConnectionUri, new { @class = "textbox", style = "width:525px; direction: ltr;" })
</div><br />

<span class="hint">@ILS.GetResource("Example"):<br /><br />
<code>mongodb://UserName:Password@localhost:27017/DataBaseName</code></span>
</div>
<br />
</div>

<div class="input-prepend"><span class="add-on inputLable">@ILS.GetResource("CreateSampleData")</span>
        <div class="input-append">
            <span class="add-on">@Html.CheckBoxFor(x => x.InstallSampleData)</span>
        </div>
</div>

</div>

<div class="form-footer">
                    <a href="@Url.Action("RestartInstall", "Install")" title="@ILS.GetResource("RestartInstallationTooltip")" class="btn">@ILS.GetResource("RestartInstallation")</a>
                    <input class="btn btn-primary" type="submit" value="@ILS.GetResource("Install")" style="width: 100px;" />
                </div>
            </div>
        </div>
    </div>        
        
<div class="throbber">
        <div class="curtain">
        </div>
        <div class="curtain-content">
            <div>
                <h1 class="throbber-header">
                    @ILS.GetResource("Installing")</h1>
                <p>
                    <img src="@Url.Content("~/content/install/images/install-synchronizing.gif")" alt="" />
                </p>
            </div>
        </div>
    </div>
}